<template>
	<div class="setupPost">
		<div class="classIndex_h">
			<router-link :to="{path: '/classIndex/teacher/classMembers', query: {id: path}}">班级成员</router-link>
			<strong><i>></i>岗位设置</strong>
		</div>
		<div class="Invite_us">
			<span>
				<img v-if="avatar_path !== ''" :src="BASE_URL + avatar_path">
				<img v-else src="../../../public/images/Group9.png">
			</span>
			<span>
				班主任<i>{{headmaster}}</i>
			</span>
			<span>
				电话<i>{{telphone}}</i>
			</span>
		</div>
		<!--  -->
		<div class="setupPost">
			<div class="setupPost_h">教师岗位</div>
			<ul class="setupPost_xx clear">
				<li class="setupPost_ls fl clear" v-for="(item, index) in teacherJob" :key="index">
					<span>{{item.job_name}}</span>
					<div class="">
						<template>
							<el-select filterable v-model="item.person_id" @change="changSelected(item.job_id, item.person_id)" placeholder="请选择">
								<el-option v-for="(list, index2) in teacherList" :label="list.name" :key="index2" :value="list.id">
								</el-option>
							</el-select>
						</template>
					</div>
				</li>
			</ul>
		</div>
		<!--  -->
		<div class="setupPost">
			<div class="setupPost_h">学生岗位</div>
			<ul class="setupPost_xx clear">
				<li class="setupPost_ls fl clear" v-for="(item, index) in studentJob" :key="index">
					<span>{{item.job_name}}</span>
					<div class="">
						<template>
							<el-select filterable @change="changSelected(item.job_id, item.person_id)" v-model="item.person_id" placeholder="请选择">
								<el-option v-for="(list, index2) in studentList" :label="list.name" :key="index2" :value="list.id">
								</el-option>
							</el-select>
						</template>
					</div>
				</li>
			</ul>
		</div>
		<!--  -->
		<div class="setupPost">
			<div class="setupPost_h">家长岗位</div>
			<ul class="setupPost_xx clear">
				<li class="setupPost_ls fl clear" v-for="(item, index) in parentJob" :key="index">
					<span>{{item.job_name}}</span>
					<div class="">
						<template>
							<el-select filterable @change="changSelected(item.job_id, item.person_id)" v-model="item.person_id" placeholder="请选择">
								<el-option v-for="(list, index2) in parentList" :key="index2" :label="list.name" :value="list.id">
								</el-option>
							</el-select>
						</template>
					</div>
				</li>
			</ul>
		</div>
	</div>
</template>
<script>
export default {
	name: '',
	data() {
		return {
			path: this.$route.query.id,
			headmaster: '',
			telphone: '',
			avatar_path: '',
			teacherJob: [],
			teacherList: [],

			studentJob: [],
			studentList: [],

			parentJob: [],
			parentList: [],
		}
	},
	watch: {

		'$store.state.changData': {
			handler(val, newval) {
				this.path = sessionStorage.getItem('classId')
				this.getHeadmaster();
				this.getTeacherList();
				this.getStudent()
				this.getParent()
			},
			immediate: true
		}
	},
	computed: {
		changData() {
			return deep_clone(this.$store.state.changData);
		},
	},
	created() {},
	methods: {
		//获取班主任
		getHeadmaster() {
			let success = (res => {
				let data = res.data;
				this.headmaster = data[0].name;
				this.telphone = data[0].telphone;
				this.avatar_path = data[0].avatar_path;
			});
			this.$ajax({
				url: 'api/org/class_something',
				method: 'get',
				params: {
					style: 11,
					classid: this.path,
					role_id: 6,
					data_type: 2
				},
				func: {
					success: success
				}
			})
		},
		//获取老师
		getTeacherList() {
			let success = (res => {
				let data = res.data;
				this.teacherJob = data.teacher_job;
				this.teacherList = data.teacher_select;
			})
			this.$ajax({
				url: 'api/org/class_something',
				method: 'get',
				params: {
					style: 5,
					classid: this.path,
					role_id: 6,
					data_type: 2
				},
				func: {
					success: success
				}
			})
		},
		//学生
		getStudent() {
			let success = (res => {
				let data = res.data;
				this.studentJob = data.student_job;
				this.studentList = data.student_select;
			})
			this.$ajax({
				url: 'api/org/class_something',
				method: 'get',
				params: {
					style: 5,
					classid: this.path,
					role_id: 4,
					data_type: 2
				},
				func: {
					success: success
				}
			})
		},
		//老师
		getParent() {
			let success = (res => {
				let data = res.data;
				this.parentJob = data.parent_job;
				this.parentList = data.parent_select;
			})
			this.$ajax({
				url: 'api/org/class_something',
				method: 'get',
				params: {
					style: 5,
					classid: this.path,
					role_id: 4,
					data_type: 2
				},
				func: {
					success: success
				}
			})
		},
		//提交--老师
		changSelected(userid, jobid) {
			let success = (res => {
				this.$message.success(res.msg)
			})
			this.$ajax({
				url: 'api/org/change_class_job',
				method: 'put',
				data: {
					classid: this.path,
					userid: userid,
					jobid: jobid
				},
				func: {
					success: success
				}
			})
		}
	}
}
</script>